﻿using DataCollection.Infrastructure;
using QRCoder;

namespace DataCollection.WinForm.Forms
{
    public partial class QRCoderForm : DCBaseForm
    {

        #region 系统事件

        public QRCoderForm()
        {
            InitializeComponent();
        }

        private void QRCoderForm_Load(object sender, EventArgs e)
        {
            string ip = Util.IPAddress();
            if (ip.Length <= 0)
            {
                ErrorNotification("无法获取设备IP，无法提供预览功能");
            }
            else
            {
                string address = string.Format("http://{0}:8090",ip);
                AddressLabel.Text = address;
                QRCodeGenerator qrGenerator = new QRCodeGenerator();
                QRCodeData qrCodeData = qrGenerator.CreateQrCode(address, QRCodeGenerator.ECCLevel.Q);
                QRCode qrCode = new QRCode(qrCodeData);
                Bitmap qrCodeImage = qrCode.GetGraphic(20);
                PictureBox1.Image = qrCodeImage;
            }
        }

        #endregion
    }
}
